<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.fengke.csc.config.HostConfig" %>
<%
	HostConfig hostConfig = (HostConfig) request.getSession().getServletContext().getAttribute("hostConfig");
%>
<!DOCTYPE html>
	<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
	<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
	<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
	<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
	<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"><!--<![endif]-->
	<head>
		<title><%=hostConfig.getWebSiteName() %></title>
		<meta name="keywords" content="<%=hostConfig.getWebSiteName() %>" />
		<meta name="description" content="<%=hostConfig.getWebSiteName() %>" />
		<jsp:include page="../gadget/include_header.jsp"></jsp:include>
	</head>
	<body>
		<!-- 头信息 Start -->
		<jsp:include page="../gadget/main_header.jsp"></jsp:include>
		<!-- 头信息 End -->
		<jsp:include page="../gadget/main_sidebar.jsp"></jsp:include>
		<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="icon-home home-icon"></i>
						<a href="#">首页</a>
					</li>
					<li class="active">商品管理</li>
				</ul><!-- .breadcrumb -->
			</div>
			<div class="page-content">
				<div class="page-header">
					<h1>
						商品分类管理
						<small>
							<i class="icon-double-angle-right"></i>
							 查看
						</small>
					</h1>
				</div><!-- /.page-header -->
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->
						
						<div style="margin-bottom: 10px">
							<form id="csc_productCategory_delete_form" action="product/deleteProductCategory.action" method="post">
								<input type="hidden" id="csc_productCategory_deletedProductCategoryIds" name="value.deletedProductCategoryIds" value="" />
							</form>
							<a href="#modal-table" onclick="preCreateProductCategory();" role="button" class="green btn btn-primary" data-toggle="modal"><i class="icon-beaker align-top bigger-125"></i>新增</a>
							<button onclick="deleteProductCategory();" class="btn btn-grey"><i class="icon-trash icon-1.5x"></i>删除</button>
						</div>

						<jsp:include page="../gadget/include_pageMessage.jsp"></jsp:include>
						
						<div class="table-responsive dataTables_wrapper">
							<table id="productCategory_list_table" class="table table-striped table-bordered table-hover dataTable">
								<thead>
									<tr>
										<th class="center">
											<label>
												<input type="checkbox" class="ace" />
												<span class="lbl"></span>
											</label>
										</th>
										<th>编号</th>
										<th>分类名称</th>
										<th>
											<i class="icon-time bigger-110 hidden-480"></i>
											创建日期
										</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<s:if test="productCategoryVOList != null && productCategoryVOList.size > 0">
										<s:iterator value="productCategoryVOList" var="productCategory" status="countIdx">
											<tr>
												<td class="center">
													<label>
														<input type="checkbox" class="ace" lang="<s:property value='#productCategory.productCategoryModel.id'/>" />
														<span class="lbl"></span>
													</label>
												</td>
												<td><s:property value='#productCategory.productCategoryModel.id'/></td>
												<td><s:property value='#productCategory.productCategoryModel.name'/></td>
												<td><s:date name='#productCategory.productCategoryModel.createDate' format="yyyy-MM-dd"/></td>
												<td>
													<a href="#modal-table" onclick="preUpdateProductCategory('<s:property value='#productCategory.productCategoryModel.id'/>', '<s:property value='#productCategory.productCategoryModel.name'/>');" role="button" class="btn btn-xs btn-primary" data-toggle="modal"><i class='icon-edit'></i>编辑</a>
												</td>
											</tr>
										</s:iterator>
									</s:if>
									<s:else>
										<tr>
											<td colspan="5" style="text-align: center">暂无数据</td>
										</tr>
									</s:else>
								</tbody>
							</table>
						</div>
						
						<div id="modal-table" class="modal fade" tabindex="-1">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header no-padding">
										<div class="table-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="hidden_modal_button">
												<span class="white">&times;</span>
											</button>
											<span id="title_flag"></span>商品分类
										</div>
									</div>

									<div class="modal-body no-padding">
										<table class="table table-striped table-bordered table-hover no-margin-bottom no-border-top">
											<tr>
												<th style="text-align: right;vertical-align: middle">
													<label class="control-label no-padding-right" for="input_productCategory_name"><span style="color: red;">*</span>商品分类：</label>
												</th>
												<td>
													<form id="edit_productCategory_form" method="post">
														<input type="hidden" name="productCategoryVO.productCategoryModel.id" id="input_productCategory_id"/>
														<input type="text" name="productCategoryVO.productCategoryModel.name" id="input_productCategory_name" class="col-xs-12 col-sm-6" />
													</form>
												</td>
											</tr>
										</table>
									</div>

									<div class="modal-footer no-margin-top">
										<button class="btn btn-sm btn-primary pull-left" onclick="submitProductCategory()">
											<i class="icon-edit"></i>
											保存
										</button>
									</div>
								</div><!-- /.modal-content -->
							</div><!-- /.modal-dialog -->
						</div><!-- PAGE CONTENT ENDS -->
						
					</div>
				</div>
			</div>
		</div>
			
	<jsp:include page="../gadget/include_script.jsp"></jsp:include>
	<script type="text/javascript">
		jQuery(function($) {
			$('#sidebar_product').addClass('open');
			$('#sidebar_product').addClass('active');
			$('#sidebar_product_category').addClass('active');
			
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
		
		});
		
		function deleteProductCategory() {
			var selectedIds = '';
			$('#productCategory_list_table').find('tr > td:first-child input:checkbox').each(function(){
				if(this.checked == true || this.checked == 'checked') {
					if(selectedIds != '') {
						selectedIds += ' ';
					}
					selectedIds += $(this).attr('lang');
				}
			});
			if($.trim(selectedIds) == '') {
				alert('请选择待删除的条目！');
				return ;
			}
			$('#csc_productCategory_deletedProductCategoryIds').attr('value', selectedIds);
			$('#csc_productCategory_delete_form').submit();
		}
		
		function preCreateProductCategory() {
			$('#title_flag').html('新增');
			$('#edit_productCategory_form').attr('action', 'product/createProductCategory.action');
		}
		
		function preUpdateProductCategory(id, name) {
			$('#title_flag').html('编辑');
			$('#input_productCategory_id').attr('value', id);
			$('#input_productCategory_name').attr('value', name);
			$('#edit_productCategory_form').attr('action', 'product/updateProductCategory.action');
		}
		
		function submitProductCategory() {
			if($.trim($('#input_productCategory_name').val()) == '') {
				$('#input_productCategory_name').focus();
			} else {
				$('#hidden_modal_button').click();
				$('#edit_productCategory_form').submit();
			}
		}
		
	</script>
	</body>
</html>